<script setup lang="ts">
import * as echarts from 'echarts';
import {useResizeObserver} from "@vueuse/core";

let myChart: echarts.ECharts | null = null

const showEcharts = () => {
  const chartDom = document.getElementById('main4');
  myChart = echarts.init(chartDom);
  let option;

  option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      bottom: '-2%',
      left: 'center',
      textStyle: {
        // color: `#000`,
      }
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center',
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          {value: 1048, name: '搜索引擎'},
          {value: 735, name: '直接访问'},
          {value: 580, name: '电子邮件'},
          {value: 300, name: '视频广告'},
        ],
      }
    ]
  };

  option && myChart.setOption(option);
}
onMounted(() => {
  showEcharts()
})

// 监听视口大小 useResizeObserver 或者在 window.addEventListener('resize',callback) 中监听
const chartElRef = ref(null)
// 在浏览器宽度改变的时候，始终保持图表宽度是页面的 100%
useResizeObserver(chartElRef, () => myChart.resize())
</script>

<template>
  <div id="main4" ref="chartElRef" w-full h-280px>

  </div>
</template>

<style scoped>

</style>